﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL.UsersTransaction;

namespace FamilyManager
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {
            txtPass.Focus();

        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            UserLoginTransaction objUserLoginTransaction = new UserLoginTransaction(txtName.Text, txtPass.Text);
            if (objUserLoginTransaction.LoginState == UserLoginTransaction.LoginResult.成功)
            {
                MainForm mainForm = MainForm.CreateInstance();
                this.Hide();
                mainForm.Show();
            }
            else
            {
                txtPass.Text = string.Empty;
                txtName.Text = string.Empty;
                txtName.Focus();
                MessageBox.Show("登录失败，请检查登录名字和密码!", "操作提示");
            }
        }



        private void btnClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void txtName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtPass.Focus();
            }
        }

        private void txtPass_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnLogin.Focus();
            }
        }
    }
}
